<?php

require_once(dirname(__FILE__) . "/../config/environment.php");
require_once(DOC_ROOT . 'doc/NameLookup.php');

$parameters =& $_GET;
if(!$parameters) $parameters =& $_POST;

$collection = @$parameters["collection"];
$name_string = @$parameters["name_string"];
$action = @$parameters["action"];
$callback = @$parameters["callback"];
$index = @$parameters["index"];

if($action) $collection .= "_" . $action;


$return = "";
if(!$collection || !$name_string || !method_exists('NameLookup', $collection))
{
    $return = "";
}else
{
    $json = NameLookup::$collection($name_string);
    $return = $json;
}


if($callback)
{
    if(!$index) $index = 0;
    echo "$callback(".json_encode($return).", $index)";
}else
{
    echo json_encode($return);
}

?>